package com.nondo.dean.security.endpoint;

import com.nondo.dean.auth.client.DeanAuthClient;
import com.nondo.dean.auth.client.annotation.LazyAutowired;
import com.nondo.dean.auth.common.annotation.HasUser;
import com.nondo.dean.auth.common.TokenPrincipalProvider;
import com.nondo.dean.auth.common.bean.TreeBean;
import com.nondo.dean.common.web.View;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DemoEndpoint {

    @Autowired
    private TokenPrincipalProvider tokenPrincipalProvider;

    @LazyAutowired
    private DeanAuthClient deanAuthClient;

    //
    @HasUser
    @RequestMapping(
            value = "/demo/index",
            method = {RequestMethod.POST, RequestMethod.GET}
    )
    public View<String> registerVerificationCodeEndpoint() {

        View<List<TreeBean>> re = deanAuthClient.requestMenuTreeOfUser();
        return View.ofOk(tokenPrincipalProvider.getTokenPrincipal().getUsername());
//        return View.ofOk(re.getMessage());
    }


}
